package cn.justforchris.system.service.impl;

import cn.justforchris.system.domain.Permission;
import cn.justforchris.system.mapper.PermissionMapper;
import cn.justforchris.system.query.PermissionQuery;
import cn.justforchris.system.service.IPermissionService;
import cn.justforchris.user.domain.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;
    @Override
    public void insertPermission(Permission permission) {
        permissionMapper.insertPermission(permission);
    }

    @Override
    public void deletePermission(Long id) {
        permissionMapper.deletePermission(id);
    }

    @Override
    public void patchDelete(Long[] ids) {
        permissionMapper.patchDelete(ids);
    }

    @Override
    public void updatePermission(Permission permission) {
        permissionMapper.updatePermission(permission);
    }

    @Override
    public Permission getPermissionById(Long id) {
        return permissionMapper.getPermissionById(id);
    }

    @Override
    public List<Permission> getAll() {
        return permissionMapper.getAll();
    }

    @Override
    public PageInfo<Permission> queryPage(PermissionQuery queryPage) {
        PageHelper.startPage(queryPage.getCurrentPage(),queryPage.getPageSize());
        List<Permission> data = permissionMapper.queryPage(queryPage);
        /*
        这里获取到的是符合传入参数currentpage和pagesize的数据,也就是说,如果不传pagesize就只有五条因为怕个size如果不传入的话就是5
        但是如果有pagesize传入就根据传入数据来
        */
        return new PageInfo<>(data);
        /*这里面就包含了pagehelper帮忙计算出来的total(总共多少条,和根据分页提取出的数据)*/
    }


}
